package dao;

import pojo.Author;
import pojo.View;
import util.JDBCUtil;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author 郝雷蒙
 * @Description
 * @date 2020/11/10 17:09
 */
public class ViewDaoImpl implements ViewDao{
    @Override
    public List<View> selectAllViews() {
        List<View> views = new ArrayList<>();

        String sql = "select * from view";

        JDBCUtil jdbcUtil = new JDBCUtil();

        ResultSet resultSet = jdbcUtil.excuteQuery(sql);

        try {
            while(resultSet.next()) {
                View view = new View();

                view.setViewId(resultSet.getInt("viewId"));
               view.setViewCount(resultSet.getInt("viewCount"));

            }

            return views;
        } catch (SQLException e) {
            e.printStackTrace();

            return null;
        } finally {
            jdbcUtil.close();
        }
    }
}

